import LogicFlow, {PolygonNode, PolygonNodeModel,h} from "@logicflow/core";

export default function registerPush (lf:LogicFlow) {
  lf.register('push', () => {
    class Node extends PolygonNode {
      getIconShape () {
        const {model} = this.props
        const {
          stroke
        } = model.getNodeStyle()
        return h(
          'svg',
          {
            x: 18,
            y: 18,
            width: 30,
            height: 30,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: stroke,
              d: 'M982.357333 352.028444L841.955556 211.399111a45.511111 45.511111 0 0 0-32.540445-13.425778 45.511111 45.511111 0 0 0-45.511111 45.511111V705.422222a102.855111 102.855111 0 1 1-204.8 0V318.577778a193.877333 193.877333 0 0 0-386.844444 0v352.711111l-63.715556-63.715556a45.511111 45.511111 0 0 0-64.398222 64.398223L182.044444 812.600889a45.511111 45.511111 0 0 0 32.085334 13.425778 45.511111 45.511111 0 0 0 45.511111-45.511111V318.577778a102.855111 102.855111 0 0 1 204.8 0v386.844444a193.877333 193.877333 0 0 0 386.844444 0V352.711111l63.715556 63.715556a45.511111 45.511111 0 0 0 32.085333 13.198222 45.511111 45.511111 0 0 0 32.312889-77.596445z'
            }
          )
        )
      }
      getShape () {
        const {model} = this.props
        const {width, height, x, y, points} = model
        const {
          fill,
          fillOpacity,
          strokeWidth,
          stroke,
          strokeOpacity,
        } = model.getNodeStyle()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        const pointsPath = points.map((point:any[]) => point.join(',')).join(' ')
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'polygon',
              {
                points: pointsPath,
                fill,
                stroke,
                strokeWidth,
                strokeOpacity,
                fillOpacity
              }
            ),
            this.getIconShape(),
            //this.getPulsShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor (data:any, graphModel:any) {
        data.text = {
          value: (data.text && data.text.value) || '',
          x: data.x,
          y: data.y + 50
        }
        super(data, graphModel)
        const lenght = 35
        this.points = [
          [lenght, 0],
          [lenght * 2, lenght],
          [lenght, lenght * 2],
          [0, lenght]
        ]
      }
    }
    return {
      view: Node,
      model: Model
    }
  })
}
